package com.cs.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cs.dao.AdminDaoImpl;
import com.cs.entity.Admin;
import com.cs.entity.Page;
import com.cs.entity.Student;
import com.cs.entity.Teacher;

@Service
@Transactional
public class AdminServiceImpl {
	@Resource
	private AdminDaoImpl aDaoImpl;
	
	//管理员登录
	public Admin admLogin(String aname,String apassword){
		Admin admin = this.aDaoImpl.admLogin(aname, apassword);
		if (admin!=null) {
			return admin;
		}else {
			return null;
		}
	}
	//查询全部学生并分页显示
	public Page<Student> findAllStudent(int pageNum,int pageSize){
		return this.aDaoImpl.findAllStudent(pageNum, pageSize);
	}
	//根据学号查询学生
	public boolean findStudentBySno(String sno) {
		Student student = this.aDaoImpl.findStudentBySno(sno);
		if (student!=null) {
			return true;
		}else {
			return false;
		}
	}
	//添加学生
	public boolean addStudent(Student student){
		//设置初始密码为123456
		student.setSpassword("123456");
		int addStudent = this.aDaoImpl.addStudent(student);
		if (addStudent>0) {
			return true;
		}else {
			return false;
		}
	}
	//删除学生
	public boolean delStudent(Integer id) {
		return this.aDaoImpl.delStudent(id);
	}
	//查询全部教师并分页显示
	public Page<Teacher> findAllTeacher(int pageNum,int pageSize){
		return this.aDaoImpl.findAllTeacher(pageNum, pageSize);
	}
	//添加学生
	public boolean addTeacher(Teacher teacher){
		//设置初始密码为123456
		teacher.setTpassword("123456");
		int addStudent = this.aDaoImpl.addTeacher(teacher);
		if (addStudent>0) {
			return true;
		}else {
			return false;
		}
	}
	//根据学号查询学生
	public boolean findTeacherByTno(String tno) {
		Teacher teacher = this.aDaoImpl.findTeacherByTno(tno);
		if (teacher!=null) {
			return true;
		}else {
			return false;
		}
	}
	//删除教师
	public boolean delTeacher(Integer id) {
		return this.aDaoImpl.delTeacher(id);
	}
}
